use file_sys::block_cache_dev::BlockCacheDevice;
use file_sys::file_disk::FileDisk;
use file_sys::block_dev::BlockDevice;

fn get_device() -> BlockCacheDevice {
    BlockCacheDevice::new(Box::new(FileDisk::new("./disk/image").unwrap()))
}

#[test]
fn test_block_cache_dev_read_write() {
    let mut device = get_device();

    device.write_block(2, &[0xee; 512]);

    let mut buf = [0; 512];
    device.read_block(2, &mut buf);

    assert_eq!(buf, [0xee; 512]);
}

#[test]
fn test_block_cache_dev_mut_ref() {
    let mut device = get_device();

    let data: &mut u64 = device.get_mut(0, 40);
    *data = std::u64::MAX;

    assert_eq!(*device.get_ref::<u64>(0, 40), std::u64::MAX);

    drop(device);

    let mut device = get_device();
    assert_eq!(*device.get_ref::<u64>(0, 40), std::u64::MAX);
}